/**
 * 
 */
package com.highveldsky.leaverequest.server.service;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.highveldsky.leaverequest.client.service.LeaveRequestService;
import com.highveldsky.leaverequest.shared.model.LeaveRequest;

/**
 * @author david
 *
 */
@SuppressWarnings("serial")
public class LeaveRequestServiceImpl extends RemoteServiceServlet implements
		LeaveRequestService {

	private static final Logger log = Logger.getLogger(LeaveRequestServiceImpl.class.getName());
	
	/* (non-Javadoc)
	 * @see com.highveldsky.leaverequest.client.service.LeaveRequestService#submitLR(com.highveldsky.leaverequest.shared.model.LeaveRequest)
	 */
	@Override
	public boolean submitLR(LeaveRequest lr) throws Exception {
		// TODO Auto-generated method stub
		log.info("LR submitted: " + lr);
		return true;
	}

	/* (non-Javadoc)
	 * @see com.highveldsky.leaverequest.client.service.LeaveRequestService#approveLR(long)
	 */
	@Override
	public boolean approveLR(long id) throws Exception {
		// TODO Auto-generated method stub
		log.info("LR approved: " + id);
		return true;
	}

	/* (non-Javadoc)
	 * @see com.highveldsky.leaverequest.client.service.LeaveRequestService#listApproversLRs(java.lang.String)
	 */
	@Override
	public List<LeaveRequest> listApproversLRs(String approver)
			throws Exception {
		// TODO Auto-generated method stub
		List<LeaveRequest> result = new ArrayList<LeaveRequest>();
		for (int i=0; i<10; i++) {
			LeaveRequest lr = new LeaveRequest();
			lr.id = i;
			lr.employeeName = "John Smith";
			lr.approverName = approver;
			lr.approverEmail = "davidjohnmac@gmail.com";
			Calendar c = Calendar.getInstance();
			c.setTime(new Date());
			c.add(Calendar.DATE, 10);  // number of days to add
			lr.firstDay = c.getTime();
			c.add(Calendar.DATE, 3);
			lr.lastDay = c.getTime();
			
			result.add(lr);
		}
		
		return result;
	}

	/* (non-Javadoc)
	 * @see com.highveldsky.leaverequest.client.service.LeaveRequestService#listEmployeesLRs(java.lang.String)
	 */
	@Override
	public List<LeaveRequest> listEmployeesLRs(String employee)
			throws Exception {
		// TODO Auto-generated method stub
		List<LeaveRequest> result = new ArrayList<LeaveRequest>();
		for (int i=0; i<10; i++) {
			LeaveRequest lr = new LeaveRequest();
			lr.id = i;
			lr.employeeName = employee;
			lr.approverName = "Joe Panda";
			lr.approverEmail = "davidjohnmac@gmail.com";
			Calendar c = Calendar.getInstance();
			c.setTime(new Date());
			c.add(Calendar.DATE, 10);  // number of days to add
			lr.firstDay = c.getTime();
			c.add(Calendar.DATE, 3);
			lr.lastDay = c.getTime();
			
			result.add(lr);
		}
		
		return result;
	}

}
